#include <iostream>
#include <vector>
using namespace std;

class Solution1
{
public:
    int minSubArrayLen(int target, vector<int>& nums)
    {
        int sum = 0, len = INT_MAX;

        for (int left = 0, right = 0; right < nums.size(); right++)
        {
            sum += nums[right];
            while (sum >= target)
            {
                len = min(len, right - left + 1);
                sum -= nums[left++];
            }
        }
        return len;
    }
};

void Tests1()
{
    vector<int> nums1 = { 2,3,1,2,4,3 };
    Solution1 s1;
    cout << s1.minSubArrayLen(7,nums1) << endl;
}

class Solution2 
{
public:
    int lengthOfLongestSubstring(string s) 
    {

        int hash[128] = { 0 };
        int ret = 0;

        for (int left = 0, right = 0; right < s.size(); right++)
        {
            hash[s[right]]++;
            while (hash[s[right]] > 1)
                hash[s[left++]]--;
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};

void Tests2()
{
    string s = "abcabcbb";
    Solution2 s2;
    cout << s2.lengthOfLongestSubstring(s) << endl;
}

int main()
{
     //Tests1();
    Tests2();
	return 0;
}